package com.wanmait.employment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.employment.entity.*;
import com.wanmait.employment.mapper.*;
import com.wanmait.employment.service.RecruitmentPostService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;

@Service
@Transactional(rollbackFor = Exception.class)
public class RecruitmentPostServiceImpl extends ServiceImpl<RecruitmentPostMapper,RecruitmentPost> implements RecruitmentPostService {
    @Resource
    private RecruitmentPostMapper recruitmentPostMapper;

    @Resource
    private CompanyMapper companyMapper;

    @Resource
    private PublisherMapper publisherMapper;

    @Resource
    private AddressMapper addressMapper;

    @Resource
    private RecruitmentEducationMapper recruitmentEducationMapper;

    @Resource
    private PositionMapper positionMapper;
    @Resource
    private PositionTypeMapper positionTypeMapper;
    @Resource
    private IndustryMapper industryMapper;

    @Resource
    private WorkExperienceMapper workExperienceMapper;

    @Resource
    private NatureWorkMapper natureWorkMapper;

    @Resource
    private ExpectedSalaryMapper expectedSalaryMapper;

    @Resource
    private JobWelfareLabelBasicsMapper jobWelfareLabelBasicsMapper;

    @Resource
    private WelfareLabelBasicsMapper welfareLabelBasicsMapper;

    @Override
    public PageInfo<RecruitmentPost> findAll(String title,int pageNum,int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        QueryWrapper<RecruitmentPost> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("job_description",title)
                .or().like("ask_sex",title)
                .or().like("recruiting_numbers",title)
                .or().like("recruitment_post_tel",title)
                .or().like("recommended_keywords",title).
                or().inSql("company_id","SELECT ID FROM company WHERE company_name like '%"+title+"%'")
                .or().inSql("publisher_id","SELECT ID FROM publisher WHERE name like '%"+title+"%'")
                .or().inSql("address_id","SELECT ID FROM address WHERE title like '%"+title+"%'")
                .or().inSql("recruitment_education_id","SELECT ID FROM recruitment_education WHERE title like '%"+title+"%'")
                .or().inSql("expected_salary_id","SELECT ID FROM expected_salary WHERE title like '%"+title+"%'")
                .or().inSql("work_experience_id","SELECT ID FROM work_experience WHERE title like '%"+title+"%'")
                .or().inSql("position_id","SELECT ID FROM position WHERE title like '%"+title+"%'")
                .or().inSql("nature_work_id","SELECT ID FROM nature_work WHERE title like '%"+title+"%'");
        List<RecruitmentPost> recruitmentPostList = recruitmentPostMapper.selectList(queryWrapper);

        PageInfo<RecruitmentPost> recruitmentPostPageInfo = new PageInfo<>(recruitmentPostList);
        recruitmentPostPageInfo.getList().forEach(recruitmentPost -> {
            List<Company> companyList = companyMapper.selectList(null);
            recruitmentPost.setCompanyList(companyList);

            List<Publisher> publisherList = publisherMapper.selectList(null);
            recruitmentPost.setPublisherList(publisherList);

            List<Address> addressList = addressMapper.selectList(null);
            recruitmentPost.setAddressList(addressList);

            List<RecruitmentEducation> recruitmentEducationList = recruitmentEducationMapper.selectList(null);
            recruitmentPost.setRecruitmentEducationList(recruitmentEducationList);

            List<Position> positionList = positionMapper.selectList(null);
            recruitmentPost.setPositionList(positionList);

            List<WorkExperience> workExperienceList = workExperienceMapper.selectList(null);
            recruitmentPost.setWorkExperienceList(workExperienceList);

            List<NatureWork> natureWorkList = natureWorkMapper.selectList(null);
            recruitmentPost.setNatureWorkList(natureWorkList);

            List<ExpectedSalary> expectedSalaryList = expectedSalaryMapper.selectList(null);
            recruitmentPost.setExpectedSalaryList(expectedSalaryList);

            //公司名称连表
            QueryWrapper<Company> companyQueryWrapper = new QueryWrapper<>();
            companyQueryWrapper.eq("id",recruitmentPost.getCompanyId());
            Company company = companyMapper.selectOne(companyQueryWrapper);
            recruitmentPost.setCompany(company);

            //发布人表连表
            QueryWrapper<Publisher> publisherQueryWrapper = new QueryWrapper<>();
            publisherQueryWrapper.eq("id",recruitmentPost.getPublisherId());
            Publisher publisher = publisherMapper.selectOne(publisherQueryWrapper);
            recruitmentPost.setPublisher(publisher);

            //地区连表
            QueryWrapper<Address> addressQueryWrapper = new QueryWrapper<>();
            addressQueryWrapper.eq("id",recruitmentPost.getCompany().getAddressId());
            Address address = addressMapper.selectOne(addressQueryWrapper);

            LambdaQueryWrapper<Address> queryWrapper1 = new LambdaQueryWrapper<>();
            queryWrapper1.eq(Address::getId,address.getParentId());
            Address address2 = addressMapper.selectOne(queryWrapper1);
            address.setCity(address2);

            LambdaQueryWrapper<Address> queryWrapper2 = new LambdaQueryWrapper<>();
            queryWrapper2.eq(Address::getId,address2.getParentId());
            Address address3 = addressMapper.selectOne(queryWrapper2);
            address.setProvince(address3);
            recruitmentPost.setAddress(address);

            //学历表连表
            QueryWrapper<RecruitmentEducation> recruitmentEducationQueryWrapper = new QueryWrapper<>();
            recruitmentEducationQueryWrapper.eq("id",recruitmentPost.getRecruitmentEducationId());
            RecruitmentEducation recruitmentEducation = recruitmentEducationMapper.selectOne(recruitmentEducationQueryWrapper);
            recruitmentPost.setRecruitmentEducation(recruitmentEducation);

            //职位表连表
            QueryWrapper<Position> positionQueryWrapper = new QueryWrapper<>();
            positionQueryWrapper.eq("id",recruitmentPost.getPositionId());
            Position position = positionMapper.selectOne(positionQueryWrapper);
            recruitmentPost.setPosition(position);

            //工作经验表连表
            QueryWrapper<WorkExperience> workExperienceQueryWrapper = new QueryWrapper<>();
            workExperienceQueryWrapper.eq("id",recruitmentPost.getWorkExperienceId());
            WorkExperience workExperience = workExperienceMapper.selectOne(workExperienceQueryWrapper);
            recruitmentPost.setWorkExperience(workExperience);

            //工作性质表连表
            QueryWrapper<NatureWork> natureWorkQueryWrapper = new QueryWrapper<>();
            natureWorkQueryWrapper.eq("id",recruitmentPost.getNatureWorkId());
            NatureWork natureWork = natureWorkMapper.selectOne(natureWorkQueryWrapper);
            recruitmentPost.setNatureWork(natureWork);

            //薪资表连表
            QueryWrapper<ExpectedSalary> expectedSalaryQueryWrapper = new QueryWrapper<>();
            expectedSalaryQueryWrapper.eq("id",recruitmentPost.getExpectedSalaryId());
            ExpectedSalary expectedSalary = expectedSalaryMapper.selectOne(expectedSalaryQueryWrapper);
            recruitmentPost.setExpectedSalary(expectedSalary);
        });
        return recruitmentPostPageInfo;
    }

    @Override
    public List<Address> getProvince(int parentId) {
        LambdaQueryWrapper<Address> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Address::getParentId,parentId);
        return addressMapper.selectList(queryWrapper);
    }

    @Override
    public Integer delete(Integer id){
        return recruitmentPostMapper.deleteById(id);
    }
//查询出发布职位信息--根据发布人--李龙
    @Override
    public PageInfo<RecruitmentPost> findByPublisherId(Integer publisherId,String title,String currentStatus, Integer pageNum, Integer pageSize,String currentDate) {
        PageHelper.startPage(pageNum,pageSize);

        LambdaQueryWrapper<RecruitmentPost> recruitmentPostLambdaQueryWrapper=new LambdaQueryWrapper<>();
        recruitmentPostLambdaQueryWrapper.eq(RecruitmentPost::getPublisherId,1).and(wrapper ->{
            wrapper.inSql(RecruitmentPost::getPositionId,"SELECT id from position where title like '%"+title+"%'").or()
                    .inSql(RecruitmentPost::getAddressId,"SELECT id from address where title like '%"+title+"%'");
        });
        int n=1;
        Calendar c=Calendar.getInstance();
        if(currentDate.equals("今天")){
            n=1;
            c.add(Calendar.DATE,-1);
        }else if(currentDate.equals("3天内")){
            n=1;
            c.add(Calendar.DATE,-3);
        }else if(currentDate.equals("1周内")){
            n=1;
            c.add(Calendar.DATE,-7);
        }else if(currentDate.equals("1个月内")){
            n=1;
            c.add(Calendar.DATE,-30);
        }else if(currentDate.equals("3个月内")){
            n=1;
            c.add(Calendar.DATE,-90);
        }else if(currentDate.equals("半年内")){
            n=1;
            c.add(Calendar.DATE,-183);
        }else if(currentDate.equals("半年以上")){
             n=0;
             c.add(Calendar.DATE,-184);
        }else if(currentDate.equals("不限")){
            n=2;
        }
        Date time=c.getTime();
        if(currentStatus.equals("草稿箱")){
            recruitmentPostLambdaQueryWrapper.eq(RecruitmentPost::getDraft,1);
            if (n==0){
                recruitmentPostLambdaQueryWrapper.ge(RecruitmentPost::getRefreshTime,time);
            }else if(n==1){
                recruitmentPostLambdaQueryWrapper.between(RecruitmentPost::getRefreshTime,time,new Date());

            }
        }else if(currentStatus.equals("已发布")){
            recruitmentPostLambdaQueryWrapper.eq(RecruitmentPost::getOffShelf,0);
            recruitmentPostLambdaQueryWrapper.eq(RecruitmentPost::getDraft,0);
            if (n==0){
                recruitmentPostLambdaQueryWrapper.ge(RecruitmentPost::getReleaseTime,time);
            }else if(n==1){
                recruitmentPostLambdaQueryWrapper.between(RecruitmentPost::getReleaseTime,time,new Date());
                System.out.println(new Date()+"++++++++++++++");
            }
        }else{
//            已下架
            recruitmentPostLambdaQueryWrapper.eq(RecruitmentPost::getOffShelf,1);
            recruitmentPostLambdaQueryWrapper.eq(RecruitmentPost::getDraft,0);
            if (n==0){
                recruitmentPostLambdaQueryWrapper.ge(RecruitmentPost::getOffShelfTime,time);
            }else if(n==1){
                recruitmentPostLambdaQueryWrapper.between(RecruitmentPost::getOffShelfTime,time,new Date());
            }

        }
       List<RecruitmentPost> recruitmentPostList= recruitmentPostMapper.selectList(recruitmentPostLambdaQueryWrapper);
       PageInfo<RecruitmentPost> pageInfo=new PageInfo<>(recruitmentPostList);
       pageInfo.getList().forEach(recruitmentPost -> {
//           查询关联职位
           LambdaQueryWrapper<Position> positionLambdaQueryWrapper=new LambdaQueryWrapper<>();
           positionLambdaQueryWrapper.eq(Position::getId,recruitmentPost.getPositionId());
           Position position=positionMapper.selectOne(positionLambdaQueryWrapper);
           recruitmentPost.setPosition(position);
//           查询关联主职位
           LambdaQueryWrapper<PositionType> positionTypeLambdaQueryWrapper=new LambdaQueryWrapper<>();
           positionTypeLambdaQueryWrapper.eq(PositionType::getId,position.getPositionTypeId());
           PositionType positionType=positionTypeMapper.selectOne(positionTypeLambdaQueryWrapper);
           recruitmentPost.setPositionType(positionType);
//           查询关联行业信息
           LambdaQueryWrapper<Industry> industryLambdaQueryWrapper=new LambdaQueryWrapper<>();
           industryLambdaQueryWrapper.eq(Industry::getId,positionType.getIndustryId());
           recruitmentPost.setIndustry(industryMapper.selectOne(industryLambdaQueryWrapper));

//           查询关联区
           LambdaQueryWrapper<Address> addressLambdaQueryWrapper=new LambdaQueryWrapper<>();
           addressLambdaQueryWrapper.eq(Address::getId,recruitmentPost.getAddressId());
           Address address=addressMapper.selectOne(addressLambdaQueryWrapper);
           recruitmentPost.setAddress(address);
//           查询关联市
           LambdaQueryWrapper<Address> cityLambadaQueryWrapper=new LambdaQueryWrapper<>();
           cityLambadaQueryWrapper.eq(Address::getId,address.getParentId());
           Address city=addressMapper.selectOne(cityLambadaQueryWrapper);
           recruitmentPost.setCity(city);
//           查询关联省
           LambdaQueryWrapper<Address> provinceQueryWrapper=new LambdaQueryWrapper<>();
           provinceQueryWrapper.eq(Address::getId,city.getParentId());
           Address province=addressMapper.selectOne(provinceQueryWrapper);
           recruitmentPost.setProvince(province);
//          查询关联薪资
           LambdaQueryWrapper<ExpectedSalary> expectedSalaryLambdaQueryWrapper=new LambdaQueryWrapper<>();
           expectedSalaryLambdaQueryWrapper.eq(ExpectedSalary::getId,recruitmentPost.getExpectedSalaryId());
           recruitmentPost.setExpectedSalary(expectedSalaryMapper.selectOne(expectedSalaryLambdaQueryWrapper));

//           查询工作经验要求
           LambdaQueryWrapper<WorkExperience> workExperienceLambdaQueryWrapper=new LambdaQueryWrapper<>();
           workExperienceLambdaQueryWrapper.eq(WorkExperience::getId,recruitmentPost.getWorkExperienceId());
           recruitmentPost.setWorkExperience(workExperienceMapper.selectOne(workExperienceLambdaQueryWrapper));
//           查询学历要求
           LambdaQueryWrapper<RecruitmentEducation> recruitmentEducationLambdaQueryWrapper=new LambdaQueryWrapper<>();
           recruitmentEducationLambdaQueryWrapper.eq(RecruitmentEducation::getId,recruitmentPost.getRecruitmentEducationId());
           recruitmentPost.setRecruitmentEducation(recruitmentEducationMapper.selectOne(recruitmentEducationLambdaQueryWrapper));
//           查询工作性质
           LambdaQueryWrapper<NatureWork> natureWorkLambdaQueryWrapper=new LambdaQueryWrapper<>();
           natureWorkLambdaQueryWrapper.eq(NatureWork::getId,recruitmentPost.getNatureWorkId());
           recruitmentPost.setNatureWork(natureWorkMapper.selectOne(natureWorkLambdaQueryWrapper));
       });
        return pageInfo;
    }
//更新发布的职位 上线、下线状态（单个或批量）--李龙
    @Override
    public void updateStatus(String idArray, String jobStatus) {
        Date date=new Date();
        String ids[]=idArray.split(",");
        LambdaQueryWrapper<RecruitmentPost> recruitmentPostLambdaQueryWrapper=new LambdaQueryWrapper<>();
        recruitmentPostLambdaQueryWrapper.in(RecruitmentPost::getId,ids);
        RecruitmentPost recruitmentPost=new RecruitmentPost();
        recruitmentPost.setDraft(false);
//        发布的职位下架
        if(jobStatus.equals("1")){
            recruitmentPost.setOffShelf(true);
            recruitmentPost.setOffShelfTime(date);
            recruitmentPostMapper.update(recruitmentPost,recruitmentPostLambdaQueryWrapper);
        }
//        hou职位上线
        if (jobStatus.equals("0")){
            recruitmentPost.setOffShelf(false);
            recruitmentPost.setRefreshTime(date);
            recruitmentPostMapper.update(recruitmentPost,recruitmentPostLambdaQueryWrapper);
        }

    }
//删除发布的职位（单个或批量）--李龙
    @Override
    public void deleteByIds(String idArray) {
        String ids[]=idArray.split(",");
        LambdaQueryWrapper<RecruitmentPost> recruitmentPostLambdaQueryWrapper=new LambdaQueryWrapper<>();
        recruitmentPostLambdaQueryWrapper.in(RecruitmentPost::getId,ids);
        List<RecruitmentPost> recruitmentPostList=recruitmentPostMapper.selectList(recruitmentPostLambdaQueryWrapper);
        recruitmentPostMapper.deleteBatchIds(recruitmentPostList);

    }

    //前台查公司主页的职位-----宋立新
    @Override
    public List<RecruitmentPost> searchList(Integer companyId) {
        QueryWrapper<RecruitmentPost> recruitmentPostQueryWrapper= new QueryWrapper<>();
        recruitmentPostQueryWrapper.eq(" company_id", companyId);
        List<RecruitmentPost> recruitmentPostList=recruitmentPostMapper.selectList(recruitmentPostQueryWrapper);
        recruitmentPostList.forEach(recruitmentPost -> {
            //           查询关联职位
            LambdaQueryWrapper<Position> positionLambdaQueryWrapper=new LambdaQueryWrapper<>();
            positionLambdaQueryWrapper.eq(Position::getId,recruitmentPost.getPositionId());
            Position position=positionMapper.selectOne(positionLambdaQueryWrapper);
            recruitmentPost.setPosition(position);
            //           查询关联主职位
            LambdaQueryWrapper<PositionType> positionTypeLambdaQueryWrapper=new LambdaQueryWrapper<>();
            positionTypeLambdaQueryWrapper.eq(PositionType::getId,position.getPositionTypeId());
            PositionType positionType=positionTypeMapper.selectOne(positionTypeLambdaQueryWrapper);
            recruitmentPost.setPositionType(positionType);
            //           查询关联行业信息
            LambdaQueryWrapper<Industry> industryLambdaQueryWrapper=new LambdaQueryWrapper<>();
            industryLambdaQueryWrapper.eq(Industry::getId,positionType.getIndustryId());
            recruitmentPost.setIndustry(industryMapper.selectOne(industryLambdaQueryWrapper));

            //           查询关联区
            LambdaQueryWrapper<Address> addressLambdaQueryWrapper=new LambdaQueryWrapper<>();
            addressLambdaQueryWrapper.eq(Address::getId,recruitmentPost.getAddressId());
            Address address=addressMapper.selectOne(addressLambdaQueryWrapper);
            recruitmentPost.setAddress(address);
            //           查询关联市
            LambdaQueryWrapper<Address> cityLambadaQueryWrapper=new LambdaQueryWrapper<>();
            cityLambadaQueryWrapper.eq(Address::getId,address.getParentId());
            Address city=addressMapper.selectOne(cityLambadaQueryWrapper);
            recruitmentPost.setCity(city);
            //           查询关联省
            LambdaQueryWrapper<Address> provinceQueryWrapper=new LambdaQueryWrapper<>();
            provinceQueryWrapper.eq(Address::getId,city.getParentId());
            Address province=addressMapper.selectOne(provinceQueryWrapper);
            recruitmentPost.setProvince(province);
            //          查询关联薪资
            LambdaQueryWrapper<ExpectedSalary> expectedSalaryLambdaQueryWrapper=new LambdaQueryWrapper<>();
            expectedSalaryLambdaQueryWrapper.eq(ExpectedSalary::getId,recruitmentPost.getExpectedSalaryId());
            recruitmentPost.setExpectedSalary(expectedSalaryMapper.selectOne(expectedSalaryLambdaQueryWrapper));

            //           查询工作经验要求
            LambdaQueryWrapper<WorkExperience> workExperienceLambdaQueryWrapper=new LambdaQueryWrapper<>();
            workExperienceLambdaQueryWrapper.eq(WorkExperience::getId,recruitmentPost.getWorkExperienceId());
            recruitmentPost.setWorkExperience(workExperienceMapper.selectOne(workExperienceLambdaQueryWrapper));
            //           查询学历要求
            LambdaQueryWrapper<RecruitmentEducation> recruitmentEducationLambdaQueryWrapper=new LambdaQueryWrapper<>();
            recruitmentEducationLambdaQueryWrapper.eq(RecruitmentEducation::getId,recruitmentPost.getRecruitmentEducationId());
            recruitmentPost.setRecruitmentEducation(recruitmentEducationMapper.selectOne(recruitmentEducationLambdaQueryWrapper));

            //薪资表连表
            QueryWrapper<ExpectedSalary> expectedSalaryQueryWrapper = new QueryWrapper<>();
            expectedSalaryQueryWrapper.eq("id",recruitmentPost.getExpectedSalaryId());
            ExpectedSalary expectedSalary = expectedSalaryMapper.selectOne(expectedSalaryQueryWrapper);
            recruitmentPost.setExpectedSalary(expectedSalary);
        });
        Collections.shuffle(recruitmentPostList); // 打乱列表顺序
        int limit = Math.min(recruitmentPostList.size(), 3); // 确定最终选取的元素数量
        recruitmentPostList = recruitmentPostList.subList(0, limit); // 截取前 limit 个元素
        return recruitmentPostList;
    }

    @Override
    public void saveOrUpdatePost(RecruitmentPost recruitmentPost, String type,String checkList) {
        //        type=0    发布
        if (type.equals("0")){
            recruitmentPost.setOffShelf(false);
            recruitmentPost.setOffShelfTime(new Date());
        }
        if (type.equals("1")){
            recruitmentPost.setDraft(true);
        }
        recruitmentPost.setExpectedSalaryId(recruitmentPost.getExpectedSalary().getId());
        recruitmentPost.setPositionId(recruitmentPost.getPositionId());
        recruitmentPost.setWorkExperienceId(recruitmentPost.getWorkExperience().getId());
        recruitmentPost.setRecruitmentEducationId(recruitmentPost.getRecruitmentEducation().getId());
        recruitmentPost.setNatureWorkId(recruitmentPost.getNatureWork().getId());
        recruitmentPost.setAddressId(recruitmentPost.getAddress().getId());
        recruitmentPost.setRefreshTime(new Date());

        if (recruitmentPost.getId()!=null){
            //        清掉原有数据
            LambdaQueryWrapper<JobWelfareLabelBasics> jobWelfareLabelBasicsLambdaQueryWrapper=new LambdaQueryWrapper<>();
            jobWelfareLabelBasicsLambdaQueryWrapper.eq(JobWelfareLabelBasics::getRecruitmentPostId,recruitmentPost.getId());
            List<JobWelfareLabelBasics> jobWelfareLabelBasics1=jobWelfareLabelBasicsMapper.selectList(jobWelfareLabelBasicsLambdaQueryWrapper);
            jobWelfareLabelBasics1.forEach(jobWelfareLabelBasics2 -> {
                jobWelfareLabelBasicsMapper.deleteById(jobWelfareLabelBasics2.getId());
            });
//        添加新数据
            recruitmentPostMapper.updateById(recruitmentPost);
            String[] strings=recruitmentPost.getJobWelfareLabelBasicsTitles();
            StringBuilder sb=new StringBuilder();
            for (String s:strings){
                sb.append("'").append(s).append("',");
            }
            String str=sb.toString();
            str=str.substring(0,str.length()-1);

            LambdaQueryWrapper<WelfareLabelBasics> wrapper=new LambdaQueryWrapper<>();
            wrapper.apply(" title in ("+str+")");
            List<WelfareLabelBasics> welfareLabelBasicsList=welfareLabelBasicsMapper.selectList(wrapper);

            for (WelfareLabelBasics welfareLabelBasics:welfareLabelBasicsList){
                JobWelfareLabelBasics jobWelfareLabelBasics=new JobWelfareLabelBasics();
                jobWelfareLabelBasics.setWelfareLabelBasiceId(welfareLabelBasics.getId());
                jobWelfareLabelBasics.setRecruitmentPostId(recruitmentPost.getId());
                jobWelfareLabelBasicsMapper.insert(jobWelfareLabelBasics);
            }
        }else{
           recruitmentPost.setReleaseTime(new Date());
           LambdaQueryWrapper<Publisher> publisherLambdaQueryWrapper=new LambdaQueryWrapper<>();
           publisherLambdaQueryWrapper.eq(Publisher::getId,recruitmentPost.getPublisherId());
           Publisher publisher=publisherMapper.selectOne(publisherLambdaQueryWrapper);
           recruitmentPost.setCompanyId(publisher.getCompanyId());

           int id= recruitmentPostMapper.insert(recruitmentPost);
            String titles[]= recruitmentPost.getJobWelfareLabelBasicsTitles();
//            String[] strings=titles.split(",");
            StringBuilder sb=new StringBuilder();
            for (String s:titles){
                sb.append("'").append(s).append("',");
            }
            String str=sb.toString();
            str=str.substring(0,str.length()-1);

            LambdaQueryWrapper<WelfareLabelBasics> wrapper=new LambdaQueryWrapper<>();
            wrapper.apply(" title in ("+str+")");
            List<WelfareLabelBasics> welfareLabelBasicsList=welfareLabelBasicsMapper.selectList(wrapper);

            for (WelfareLabelBasics welfareLabelBasics:welfareLabelBasicsList){
                JobWelfareLabelBasics jobWelfareLabelBasics=new JobWelfareLabelBasics();
                jobWelfareLabelBasics.setWelfareLabelBasiceId(welfareLabelBasics.getId());
                jobWelfareLabelBasics.setRecruitmentPostId(id);
                jobWelfareLabelBasicsMapper.insert(jobWelfareLabelBasics);
            }
        }
    }

    @Override
    public RecruitmentPost findById(Integer id) {
        LambdaQueryWrapper<RecruitmentPost> recruitmentPostLambdaQueryWrapper=new LambdaQueryWrapper<>();
        recruitmentPostLambdaQueryWrapper.eq(RecruitmentPost::getId,id);
//        获取薪资列表
        RecruitmentPost recruitmentPost=recruitmentPostMapper.selectOne(recruitmentPostLambdaQueryWrapper);
        recruitmentPost.setExpectedSalaryList(expectedSalaryMapper.selectList(null));
//        查询关联薪资
        LambdaQueryWrapper<ExpectedSalary> expectedSalaryLambdaQueryWrapper=new LambdaQueryWrapper<>();
        expectedSalaryLambdaQueryWrapper.eq(ExpectedSalary::getId,recruitmentPost.getExpectedSalaryId());
        recruitmentPost.setExpectedSalary(expectedSalaryMapper.selectOne(expectedSalaryLambdaQueryWrapper));
//        获取行业类型
        LambdaQueryWrapper<Position> positionLambdaQueryWrapper=new LambdaQueryWrapper<>();
        positionLambdaQueryWrapper.eq(Position::getId,recruitmentPost.getPositionId());
        Position position=positionMapper.selectOne(positionLambdaQueryWrapper);
        recruitmentPost.setPosition(position);

        LambdaQueryWrapper<PositionType> positionTypeLambdaQueryWrapper=new LambdaQueryWrapper<>();
        positionTypeLambdaQueryWrapper.eq(PositionType::getId,position.getPositionTypeId());
        PositionType positionType=positionTypeMapper.selectOne(positionTypeLambdaQueryWrapper);
        recruitmentPost.setPositionType(positionType);

        LambdaQueryWrapper<Industry> industryLambdaQueryWrapper=new LambdaQueryWrapper<>();
        industryLambdaQueryWrapper.eq(Industry::getId,positionType.getIndustryId());
        Industry industry=industryMapper.selectOne(industryLambdaQueryWrapper);
        recruitmentPost.setIndustry(industry);

//        获取工作经验时长
        LambdaQueryWrapper<WorkExperience> workExperienceLambdaQueryWrapper=new LambdaQueryWrapper<>();
        workExperienceLambdaQueryWrapper.eq(WorkExperience::getId,recruitmentPost.getWorkExperienceId());
        WorkExperience workExperience=workExperienceMapper.selectOne(workExperienceLambdaQueryWrapper);
        recruitmentPost.setWorkExperience(workExperience);

//        获取学历
        LambdaQueryWrapper<RecruitmentEducation> recruitmentEducationLambdaQueryWrapper=new LambdaQueryWrapper<>();
        recruitmentEducationLambdaQueryWrapper.eq(RecruitmentEducation::getId,recruitmentPost.getRecruitmentEducationId());
        RecruitmentEducation recruitmentEducation=recruitmentEducationMapper.selectOne(recruitmentEducationLambdaQueryWrapper);
        recruitmentPost.setRecruitmentEducation(recruitmentEducation);
//        获取工作类型
        LambdaQueryWrapper<NatureWork> natureWorkLambdaQueryWrapper=new LambdaQueryWrapper<>();
        natureWorkLambdaQueryWrapper.eq(NatureWork::getId,recruitmentPost.getNatureWorkId());
        NatureWork natureWork=natureWorkMapper.selectOne(natureWorkLambdaQueryWrapper);
        recruitmentPost.setNatureWork(natureWork);
//        获取区
        LambdaQueryWrapper<Address> addressLambdaQueryWrapper=new LambdaQueryWrapper<>();
        addressLambdaQueryWrapper.eq(Address::getId,recruitmentPost.getAddressId());
        Address address=addressMapper.selectOne(addressLambdaQueryWrapper);
        recruitmentPost.setAddress(address);
//        获取市
        LambdaQueryWrapper<Address> addressLambdaQueryWrapper1=new LambdaQueryWrapper<>();
        addressLambdaQueryWrapper1.eq(Address::getId,address.getParentId());
        Address city=addressMapper.selectOne(addressLambdaQueryWrapper1);
        recruitmentPost.setCity(city);
//        获取省
        LambdaQueryWrapper<Address> addressLambdaQueryWrapper2=new LambdaQueryWrapper<>();
        addressLambdaQueryWrapper2.eq(Address::getId,city.getParentId());
        Address province=addressMapper.selectOne(addressLambdaQueryWrapper2);
        recruitmentPost.setProvince(province);
//        获取职位福利标签
        LambdaQueryWrapper<JobWelfareLabelBasics> jobWelfareLabelBasicsLambdaQueryWrapper=new LambdaQueryWrapper<>();
        jobWelfareLabelBasicsLambdaQueryWrapper.eq(JobWelfareLabelBasics::getRecruitmentPostId,recruitmentPost.getId());
        List<JobWelfareLabelBasics> jobWelfareLabelBasicsList=jobWelfareLabelBasicsMapper.selectList(jobWelfareLabelBasicsLambdaQueryWrapper);
        jobWelfareLabelBasicsList.forEach(jobWelfareLabelBasics1 -> {
            LambdaQueryWrapper<WelfareLabelBasics> wrapper=new LambdaQueryWrapper<>();
            wrapper.eq(WelfareLabelBasics::getId,jobWelfareLabelBasics1.getWelfareLabelBasiceId());
            WelfareLabelBasics welfareLabelBasics=welfareLabelBasicsMapper.selectOne(wrapper);
            jobWelfareLabelBasics1.setWelfareLabelBasics(welfareLabelBasics);
        });
        String[] strs = new String[jobWelfareLabelBasicsList.size()];
        for (int i=0;i<jobWelfareLabelBasicsList.size();i++){
            strs[i]=jobWelfareLabelBasicsList.get(i).getWelfareLabelBasics().getTitle();
//            System.out.println(jobWelfareLabelBasicsList.get(i).getWelfareLabelBasics().getTitle()+"22222222222222");
        }
        System.out.println(strs[1]+"---");
        recruitmentPost.setJobWelfareLabelBasicsTitles(strs);
//        recruitmentPost.setJobWelfareLabelBasicsList(jobWelfareLabelBasicsList);


        return recruitmentPost;

    }


}
